home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / borland / tpwn31.zip / PASCAL.ZIP / TOOLHELP.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-06  |  15KB  |  546 lines

  1.  
  2.  
  3. {*******************************************************}
  4. {                                                       }
  5. {       Turbo Pascal for Windows Run-time Library       }
  6. {       Windows 3.1 API Interface Unit                  }
  7. {                                                       }
  8. {       Copyright (c) 1991 Borland International        }
  9. {                                                       }
  10. {*******************************************************}
  11.  
  12. unit TOOLHELP;
  13.  
  14. interface
  15.  
  16. uses WinTypes;
  17.  
  18.  
  19. { General symbols }
  20. const
  21.   max_Data = 11;
  22.   max_Path = 255;
  23.   max_Module_Name =  8 + 1;
  24.   Max_ClassName = 255;
  25.  
  26. { Global heap walking }
  27.  
  28. type
  29.  
  30.   PGlobalInfo = ^TGlobalInfo;
  31.   TGlobalInfo = record
  32.     dwSize: Longint;
  33.     wcItems: Word;
  34.     wcItemsFree: Word;
  35.     wcItemsLRU: Word;
  36.   end;
  37.  
  38.   PGlobalEntry = ^TGlobalEntry;
  39.   TGlobalEntry = record
  40.     dwSize: Longint;
  41.     dwAddress: Longint;
  42.     dwBlockSize: Longint;
  43.     hBlock: THandle;
  44.     wcLock: Word;
  45.     wcPageLock: Word;
  46.     wFlags: Word;
  47.     wHeapPresent: Bool;
  48.     hOwner: THandle;
  49.     wType: Word;
  50.     wData: Word;
  51.     dwNext: Longint;
  52.     dwNextAlt: Longint;
  53.   end;
  54.  
  55. const
  56. { GlobalFirst()/GlobalNext() flags }
  57.   global_All = 0;
  58.   global_LRU = 1;
  59.   global_Free = 2;
  60.  
  61. { TGlobalEntry.wType entries }
  62.   gt_Unknown = 0;
  63.   gt_DGroup = 1;
  64.   gt_Data = 2;
  65.   gt_Code = 3;
  66.   gt_Task = 4;
  67.   gt_Resource = 5;
  68.   gt_Module = 6;
  69.   gt_Free = 7;
  70.   gt_Internal = 8;
  71.   gt_Sentinel = 9;
  72.   gt_BurgerMaster = 10;
  73.  
  74. { If TGlobalEntry.wType = gt_Resource, the following is TGlobalEntry.wData: }
  75.   gd_UserDefined = 0;
  76.   gd_CursorComponent = 1;
  77.   gd_Bitmap = 2;
  78.   gd_IconComponent = 3;
  79.   gd_Menu = 4;
  80.   gd_Dialog = 5;
  81.   gd_String = 6;
  82.   gd_FontDir = 7;
  83.   gd_Font = 8;
  84.   gd_Accelerators = 9;
  85.   gd_RCData = 10;
  86.   gd_ErrTable = 11;
  87.   gd_Cursor = 12;
  88.   gd_Icon = 14;
  89.   gd_NameTable = 15;
  90.   gd_Max_Resource = 15;
  91.  
  92. { TGlobalEntry.wFlags }
  93.   gf_PDB_Owner = $100;    { Low byte us KERNAL flags }
  94.  
  95. function GlobalInfo(lpGlobalInfo: PGlobalInfo): Bool;
  96. function GlobalFirst(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
  97. function GlobalNext(lpGlobal: PGlobalEntry; wFlags: Word): Bool;
  98. function GlobalEntryHandle(lpGlobal: PGlobalEntry; hItem: THandle): Bool;
  99. function GlobalEntryModule(lpGlobal: PGlobalEntry; hModule: THandle; wSeg: Word): Bool;
  100. function GlobalHandleToSel(hMem: THandle): Word;
  101.  
  102. { Local heap walking }
  103. type
  104.   PLocalInfo = ^TLocalInfo;
  105.   TLocalInfo = record
  106.     dwSize: Longint;
  107.     wcItems: Word;
  108.   end;
  109.  
  110.   PLocalEntry = ^TLocalEntry;
  111.   TLocalEntry = record
  112.     dwSize: Longint;
  113.     hHandle: THandle;
  114.     wAddress: Word;
  115.     wSize: Word;
  116.     wFlags: Word;
  117.     wcLock: Word;
  118.     wType: Word;
  119.     hHeap: Word;
  120.     wHeapType: Word;
  121.     wNext: Word;
  122.   end;
  123.  
  124. const
  125.  
  126. { TLocalEntry.wHeapType flags }
  127.   Normal_Heap = 0;
  128.   User_Heap = 1;
  129.   gdi_Heap = 2;
  130.  
  131. { TLocalEntry.wFlags }
  132.   lf_Fixed = 1;
  133.   lf_Free = 2;
  134.   lf_Moveable = 4;
  135.  
  136. { TLocalEntry.wType }
  137.   lt_Normal = 0;
  138.   lt_Free = $FF;
  139.   lt_GDI_Pen = 1;  { lt_GDI_* is for GDI's heap }
  140.   lt_GDI_Brush = 2;
  141.   lt_GDI_Font = 3;
  142.   lt_GDI_Palette = 4;
  143.   lt_GDI_Bitmap = 5;
  144.   lt_GDI_RGN = 6;
  145.   lt_GDI_DC = 7;
  146.   lt_GDI_Disabled_DC = 8;
  147.   lt_GDI_MetaDC = 9;
  148.   lt_GDI_MetaFile = 10;
  149.   lt_GDI_Max = lt_GDI_MetaFile;
  150.   lt_User_Class = 1;  { lt_USER_* is for USER's heap }
  151.   lt_User_Wnd = 2;
  152.   lt_User_String = 3;
  153.   lt_User_Menu = 4;
  154.   lt_User_Clip = 5;
  155.   lt_User_CBox = 6;
  156.   lt_User_Palette = 7;
  157.   lt_User_ED = 8;
  158.   lt_User_BWL = 9;
  159.   lt_User_OwnerDraw = 10;
  160.   lt_User_SPB = 11;
  161.   lt_User_CheckPoint = 12;
  162.   lt_User_DCE = 13;
  163.   lt_User_MWP = 14;
  164.   lt_User_Prop = 15;
  165.   lt_User_LBIV = 16;
  166.   lt_User_Misc = 17;
  167.   lt_User_Atoms = 18;
  168.   lt_User_LockInputState = 19;
  169.   lt_User_HookList = 20;
  170.   lt_User_UserSeeUserDoAlloc = 21;
  171.   lt_User_HotKeyList = 22;
  172.   lt_User_PopUpMenu = 23;
  173.   lt_User_HandleTable = 32;
  174.   lt_User_Max = lt_User_HandleTable;
  175.  
  176. function LocalInfo(lpLocal: PLocalInfo; hHeap: THandle): Bool;
  177. function LocalFirst(lpLocal: PLocalEntry; hHeap: THandle): Bool;
  178. function LocalNext(lpLocal: PLocalEntry): Boolean;
  179.  
  180.  
  181. { Stack Tracing }
  182. type
  183.  
  184.   PStackTraceEntry = ^TStackTraceEntry;
  185.   TStackTraceEntry = record
  186.     dwSize: Longint;
  187.     hTask: THandle;
  188.     wSS: Word;
  189.     wBP: Word;
  190.     wCS: Word;
  191.     wIP: Word;
  192.     hModule: THandle;
  193.     wSegment: Word;
  194.     wFlags: Word;
  195.   end;
  196.  
  197. const
  198. { TStackTraceEntry.wFlags values }
  199.   frame_Far = 0;
  200.   frame_Near = 1;
  201.  
  202. function StackTraceFirst(lpStackTrace: PStackTraceEntry; hTask: THandle): Bool;
  203. function StackTraceCSIPFirst(lpStackTrace: PStackTraceEntry;
  204.                              wSS, wCS, wIP, wBP: Word): Bool;
  205. function StackTraceNext(lpStackTrace: PStackTraceEntry): Bool;
  206.  
  207. { Module list walking }
  208. type
  209.   PModuleEntry = ^TModuleEntry;
  210.   TModuleEntry = record
  211.     dwSize: Longint;
  212.     szModule : array[0..max_Module_Name + 1] of Char;
  213.     hModule: THandle;
  214.     wUsageFlags: Word;
  215.     szExePath: array[0..max_Path + 1] of Char;
  216.     wNext: Word;
  217.   end;
  218.  
  219. function ModuleFirst(lpModule: PModuleEntry): Bool;
  220. function ModuleNext(lpModule: PModuleEntry): Bool;
  221. function ModuleFindName(lpModule: PModuleEntry; lpstrName: PChar): THandle;
  222. function ModuleFindHandle(lpModule: PModuleEntry; hModule: THandle): THandle;
  223.  
  224.  
  225. { Task list walking }
  226. type
  227.  
  228.   PTaskEntry = ^TTaskEntry;
  229.   TTaskEntry = record
  230.     dwSize: Longint;
  231.     hTask: THandle;
  232.     hTaskParent: THandle;
  233.     hInst: THandle;
  234.     hModule: THandle;
  235.     wSS: Word;
  236.     wSP: Word;
  237.     wStackTop: Word;
  238.     wStackMinimum: Word;
  239.     wStackBottom: Word;
  240.     wcEvents: Word;
  241.     hQueue: THandle;
  242.     szModule: array[0..max_Module_Name + 1] of Char;
  243.     wPSPOffset: Word;
  244.     hNext: THandle;
  245.   end;
  246.  
  247. function TaskFirst(lpTask: PTaskEntry): Bool;
  248. function TaskNext(lpTask: PTaskEntry): Bool;
  249. function TaskFindHandle(lpTask: PTaskEntry; hTask: THandle): Bool;
  250. function TaskSetCSIP(hTask: THandle; wCS, wIP: Word): Longint;
  251. function TaskGetCSIP(hTask: THandle): Longint;
  252. function TaskSwitch(hTask: THandle; dwNewCSIP: Longint): Bool;
  253.  
  254. { Window Class enumeration }
  255. type
  256.   PClassEntry = ^TClassEntry;
  257.   TClassEntry = record
  258.     dwSize: Longint;
  259.     hInst: THandle;
  260.     szClassName: array[0..Max_ClassName + 1] of Char;
  261.     wNext: Word;
  262.   end;
  263.  
  264. function ClassFirst(lpClass: PClassEntry): Bool;
  265. function ClassNext(lpClass: PClassEntry): Bool;
  266.  
  267.  
  268. type
  269.  
  270. { Information functions }
  271.   PMemManInfo = ^TMemManInfo;
  272.   TMemManInfo = record
  273.     dwSize: Longint;
  274.     dwLargestFreeBlock: Longint;
  275.     dwMaxPagesAvailable: Longint;
  276.     dwMaxPagesLockable: Longint;
  277.     dwTotalLinearSpace: Longint;
  278.     dwTotalUnlockedPages: Longint;
  279.     dwFreePages: Longint;
  280.     dwTotalPages: Longint;
  281.     dwFreeLinearSpace: Longint;
  282.     dwSwapFilePages: Longint;
  283.     wPageSize: Word;
  284.   end;
  285.  
  286. function MemManInfo(lpEnhMode: PMemManInfo): Bool;
  287.  
  288.  
  289. type
  290.   PSysHeapInfo = ^TSysHeapInfo;
  291.   TSysHeapInfo = record
  292.     dwSize: Longint;
  293.     wUserFreePercent: Word;
  294.     wGDIFreePercent: Word;
  295.     hUserSegment: THandle;
  296.     hGDISegment: THandle;
  297.   end;
  298.  
  299. function SystemHeapInfo(lpSysHeap: PSysHeapInfo): Bool;
  300.  
  301.  
  302. { Interrupt Handling }
  303.  
  304. const
  305.  
  306. { Hooked interrupts }
  307.   int_Div0            = 0;
  308.   int_1               = 1;
  309.   int_3               = 3;
  310.   int_UDInstr         = 6;
  311.   int_StkFault        = 12;
  312.   int_GPFault         = 13;
  313.   int_BadPageFault    = 14;
  314.   int_CtlAltSysRq     = 256;
  315.  
  316. { TOOLHELP Interrupt callbacks registered with InterruptRegister should
  317.  *  always be written in assembly language.  The stack frame is not
  318.  *  compatible with high level language conventions.
  319.  *
  320.  *  This stack frame looks as follows to the callback.  All registers
  321.  *  should be preserved across this callback to allow restarting fault.
  322.  *               ------------
  323.  *               |   Flags  |  [SP + 0Eh]
  324.  *               |    CS    |  [SP + 0Ch]
  325.  *               |    IP    |  [SP + 0Ah]
  326.  *               |  Handle  |  [SP + 08h]
  327.  *               |Exception#|  [SP + 06h]
  328.  *               |    AX    |  [SP + 04h]  AX Saved to allow MakeProcInst